package com.fightingFish.user.service.impl;

import com.fightingFish.user.bean.Administrator;
import com.fightingFish.user.bean.GetUser;
import com.fightingFish.user.bean.Gift;
import com.fightingFish.user.bean.User;
import com.fightingFish.user.dao.AdministratorDao;
import com.fightingFish.user.dao.impl.AdministratorDaoImpl;
import com.fightingFish.user.service.AdministratorService;

import java.util.ArrayList;
import java.util.List;

public class AdministratorServiceImpl implements AdministratorService {
    private AdministratorDao ad = new AdministratorDaoImpl();

    /**
     * 管理员的登录业务方法
     *
     * @param administrator
     * @return
     */
    @Override
    public String
    managerLogin(Administrator administrator) {
        Administrator queryAdministrator = ad.queryAdministrator(administrator.getAccount());

        if (queryAdministrator == null) {
            return "管理员账户不存在";
        } else if (!(queryAdministrator.getPwd().equals(administrator.getPwd()))) {
            return "管理员账户和密码不匹配";
        }
        return "登录成功";
    }

    /**
     * 根据用户ID管理用户状态
     * @param userId
     * @return
     */
    @Override
    public String userManage(int userId,int state) {
        if (ad.userManage(userId,state)){
            return "用户状态修改成功";
        }
        return "用户状态修改失败";
    }


    /**
     * 添加礼物
     * @param giftName
     * @param giftPrice
     * @param giftImgUrl
     * @return 返回礼物集合
     */
    @Override
    public List<Gift> add( String giftName, double giftPrice, String giftImgUrl) {
        boolean add = ad.addGift(giftName,giftPrice,giftImgUrl);
        if(add){
            return ad.queryGiftAll();
        }
        return null;
    }
    /**
     * 移除指定礼物
     * @param giftId
     * @return
     */
    @Override
    public List<Gift> remove(int giftId) {
        boolean remove = ad.removeGift(giftId);
        if(remove){
            return ad.queryGiftAll();
        }
        return null;
    }
    /**
     * 修改指定礼物信息
     * @param giftId
     * @param giftName
     * @param giftPrice
     * @param giftImgUrl
     * @return
     */
    @Override
    public List<Gift> update(int giftId, String giftName, double giftPrice, String giftImgUrl) {
        boolean update = ad.updateGift(giftId,giftName,giftPrice,giftImgUrl);
        if(update){
            return ad.queryGiftAll();
        }
        return null;
    }

    @Override
    public List<User> getUserAll() {
        return ad.getUserAll();
    }


    /**
     * 方法概述： 获取全部礼物信息
     * @return
     */
    @Override
    public List<Gift> getGift() {
        return ad.getGift();
    }

    /**
     * 方法概述： 获取所有消费总金额
     * @return
     */
    @Override
    public double getPriceAll() {
        List<Double> priceAll= ad.getPriceAll();
        double price = 0;
        for (double l:priceAll) {
            price += l;
        }
        double a = (double) Math.round((price/10000)*100)/100;
        return a;

    }

    /**
     * 方法概述：获取所有用户的充值金额
     * @return
     */
    @Override
    public double rechargeAmount() {
        List<Double> priceAll= ad.rechargeAmount();
        double price = 0;
        for (double l:priceAll) {
            price += l;
        }
//        System.out.println(price/10000);
//        return price/10000;
        double a = (double) Math.round((price/10000)*100)/100;

        return a;
    }


}
